<?php

class Photo	extends  Sitebase  
{
	public function getName()
	{
		return '的相册';
	}
	public function showTpl()
	{
			
		$param['MOD_ID'] = $this->mod_E->id;
		$param['MOD_TITLE'] = $this->current_room_E->name.$this->getName();
		$modify_url = $this->action->getUrl("index","mod","photo",array("siteid"=>$this->site_E->id,"roomid"=>$this->current_room_E->id,"modid"=>$this->mod_E->id));
		$param['MODIFY_URL'] = $modify_url;
		$tplshow = $this->getShowTpl($param);
		$data['html'] = $tplshow;
		$data['error'] = 0;
		return $data;
	}
	public function showSettingTpl()
	{
		$action = $this->action->getUrl("index","setting","modsetting",
								array("siteid"=>$this->site_E->id,
									   "roomid"=>$this->current_room_E->id,
									   "modid" =>$this->mod_E->id));
		
		$param['ACTION'] = $action;
		$param['MOD_TITLE'] = $this->mod_E->title;
		$del_url = $this->action->getUrl("index","setting","moddel",array("siteid"=>$this->site_E->id,"roomid"=>$this->current_room_E->id,"modid"=>$this->mod_E->id));
		$param['DEL_URL'] = $del_url;						
		$tplsetting = $this->getSettingTpl($param);
		$data['error'] = 0;
		$data['html'] = $tplsetting;
		return $data;
	}
	public function modsetting(&$mod_E, $request)
	{
		$name = $request->get('name');
		$mod_E->title = $name;
		$data['r'] = 0;
		return $data;
	}
	public function moddel(&$mod_E, &$current_room_E)
	{
		if(Photos::getCount($mod_E->id) > 0)
		{
			$data['r'] = 1;
			$data['error'] = '请先清空内容，再删除。';
		}
		else 
		{
			$modsort = $current_room_E->modsort;
			$modsort_arr = unserialize($modsort);
			$modsort_l = str_replace($mod_E->id.',', '', $modsort_arr['l']);
			if(!empty($modsort_l))
			$modsort_arr['l'] = $modsort_l;  
			$current_room_E->modsort = serialize($modsort_arr);
			$mod_E->delete();
			$data['r'] = 0;
		
		}
		return $data;
	}
	private function getSettingTpl($param)
	{
		$tplsetting = '
		<form action="'.$param['ACTION'].'" method="post">
			<fieldset>    
				<div class="item">
					<label>应用名称：</label>
					<input type="text" name="name" size="15" maxlength="15" value="'.$param['MOD_TITLE'].'">    
				</div>
				
				<div class="item-submit">
					<span class="bn-flat-hot"><input type="submit" value="保存"></span>
					<a href="#" class="a_cancel_setting_panel">取消</a>
					<span class="setting-panel-ops">
						<a href="'.$param['DEL_URL'].'" class="a_delete_mod" title="真的要删除此应用?">删除</a>
					</span>    
				</div>  
			</fieldset>
		</form>';
		return $tplsetting;
	}
	private function getShowTpl($param)
	{
			$showtpl = '
		<div class="mod sort" id="'.$param['MOD_ID'].'">    
			<div class="hd">
				<h2>
					<span>'.$param['MOD_TITLE'].'</span>
					<span class="pl">
					( <a href="'.$param['MODIFY_URL'].'">添加相册</a> )        
					</span>
				</h2>
				<div class="edit">
					<a href="#"  class="a_lnk_mod_setting">设置</a>
				</div> 
			</div>
			<div class="bd">
			<div class="widget-photo-list"><ul class="list-s"></ul></div>
			</div>
		</div>';
		return $showtpl;
	}
}

?>
